package com.boliq.lol.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.boliq.lol.R;
import com.boliq.lol.bean.MenuBean;
import com.google.android.material.appbar.AppBarLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 * ================================================
 * 作者: BLQ_SSNB
 * 日期：2021/2/20
 * 邮箱: blq_ssnb@outlook.com
 * 修改次数: 1
 * 描述:
 *      添加描述
 * ================================================
 * </pre>
 */
public class MenuAdapter extends RecyclerView.Adapter<MenuAdapter.MViewHolder> {

    private List<MenuBean> mData;

    public MenuAdapter() {
        mData = new ArrayList<>();
    }

    @NonNull
    @Override
    public MenuAdapter.MViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_menu, parent, false);
        return new MViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(@NonNull MViewHolder holder, int position) {
        MenuBean bean = mData.get(position);
        holder.icon.setImageResource(bean.getIcon());
        holder.title.setText(bean.getTitle());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public void addData(MenuBean bean) {
        mData.add(bean);
        notifyItemInserted(mData.size());
    }

    public void addData(List<MenuBean> data) {
        int lastSize = mData.size();
        mData.addAll(data);
        notifyItemRangeInserted(lastSize, data.size());
    }

    public static class MViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon;
        private TextView title;

        public MViewHolder(@NonNull View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.img_menu_icon);
            title = itemView.findViewById(R.id.tv_menu_title);
        }
    }
}
